package com.kingdee.eas.custom.hr.attendance.app;

import java.util.Date;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.common.DateUtils;
import com.kingdee.eas.custom.hr.attendance.ScheduleChangeEntryInfo;
import com.kingdee.eas.framework.DataBaseInfo;
import com.kingdee.eas.hr.base.HRBillBaseEntryInfo;
import com.kingdee.eas.hr.base.HRBillStateEnum;
import com.kingdee.eas.hr.base.app.HRBillBizBean;
import com.kingdee.eas.util.app.DbUtil;

public class ScheduleChangeBizBean extends HRBillBizBean {

	public void _addnew(Context arg0, IObjectPK arg1, IObjectValue arg2)
			throws BOSException, EASBizException {

	}

	public void _beforeEffectBeforeBackJob(Context arg0,
			HRBillBaseEntryInfo arg1) throws BOSException, EASBizException {

	}

	public void _beforeEffectOnBackJob(Context arg0, HRBillBaseEntryInfo arg1)
			throws BOSException, EASBizException {

	}

	public void _beforeEffectOnNoJob(Context arg0, HRBillBaseEntryInfo arg1)
			throws BOSException, EASBizException {

	}

	public void _check(Context arg0, IObjectPK arg1, IObjectValue arg2)
			throws BOSException, EASBizException {

	}

	public void _delete(Context arg0, IObjectPK arg1) throws BOSException,
			EASBizException {

	}

	public void _entryEffect(Context ctx, HRBillBaseEntryInfo entry)
			throws BOSException, EASBizException {
		ScheduleChangeEntryInfo scheduleChangeEntryInfo = (ScheduleChangeEntryInfo) entry;

		PersonInfo person = scheduleChangeEntryInfo.getPerson();

		Date date = scheduleChangeEntryInfo.getChangeDate();

//		String currentDate = DateUtils.getCurrentDateStr();
//		String changeDate = DateUtils.date2String(date, DateUtils.FORMAT_YMD);
//
//		if (changeDate.compareTo(currentDate) < 0) {
//			return;
//		}

		DataBaseInfo wtz = scheduleChangeEntryInfo.getTargetWorkTimeZone();

		String sql = null;
		if (wtz.getId().getType().toString().equals("67912D14")) {
			sql = "/*dialect*/UPDATE T_KQ_PERSONSCHEDULE SET FWORKTIMEZONEID=?,FRESTID=? WHERE FPERSONID=? AND TO_CHAR(FSCHEDULEDATE,'YYYY-MM-DD')=?";
		} else {
			sql = "/*dialect*/UPDATE T_KQ_PERSONSCHEDULE SET FRESTID=?, FWORKTIMEZONEID=? WHERE FPERSONID=? AND TO_CHAR(FSCHEDULEDATE,'YYYY-MM-DD')=?";
		}

		DbUtil.execute(ctx, sql, new Object[] {
				wtz.getId().toString(),
				null,
				person.getId().toString(),
				com.kingdee.eas.custom.common.DateUtils.date2String(date,
						"yyyy-MM-dd") });
	}

	public void _processBeforeAddNew(Context arg0, IObjectValue arg1)
			throws BOSException, EASBizException {

	}

	public void _setBillState(Context arg0, BOSUuid arg1, HRBillStateEnum arg2)
			throws BOSException, EASBizException {
	}

	public void _update(Context arg0, IObjectPK arg1, IObjectValue arg2)
			throws BOSException, EASBizException {

	}
}
